package com.appsindy.common.vo;

import java.util.Set;
import java.util.HashSet;
//import java.util.Iterator;
//import java.util.List;
//import org.apache.struts2.ServletActionContext;
//import org.springframework.web.context.WebApplicationContext;
//import org.springframework.web.context.support.WebApplicationContextUtils;

public class UserVO {
    
    private int userId;
    private int orgId;
    private String password;
    private int status;
    private String name;
    private String accessAmount;
    private String remark;
    private java.util.Date accessBeginTime;
    private java.util.Date accessEndTime;
    private String serverName;
    private boolean restricLogin;
    private String primaryIP;
    private String secondaryIP;
    private int loginFlag;
    private int loginCount;
    private int iD;
    private Set<UserGroupVO> userGroupVO = new HashSet<UserGroupVO>();
    
    private boolean viewFlag = true;
    private boolean editFlag = false;
    private boolean deleteFlag = false;
    
    public UserVO() {}

    public int getUserId() {
        return userId;
    }
    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }

    public int getStatus() {
        return status;
    }
    public void setStatus(int status) {
        this.status = status;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    public String getAccessAmount() {
        return accessAmount;
    }
    public void setAccessAmount(String accessAmount) {
        this.accessAmount = accessAmount;
    }

    public String getRemark() {
        return remark;
    }
    public void setRemark(String remark) {
        this.remark = remark;
    }

    public java.util.Date getAccessBeginTime() {
        return accessBeginTime;
    }
    public void setAccessBeginTime(java.util.Date accessBeginTime) {
        this.accessBeginTime = accessBeginTime;
    }

    public java.util.Date getAccessEndTime() {
        return accessEndTime;
    }
    public void setAccessEndTime(java.util.Date accessEndTime) {
        this.accessEndTime = accessEndTime;
    }

    public String getServerName() {
        return serverName;
    }
    public void setServerName(String serverName) {
        this.serverName = serverName;
    }

    public boolean isRestricLogin() {
        return restricLogin;
    }
    public void setRestricLogin(boolean restricLogin) {
        this.restricLogin = restricLogin;
    }

    public String getPrimaryIP() {
        return primaryIP;
    }
    public void setPrimaryIP(String primaryIP) {
        this.primaryIP = primaryIP;
    }

    public String getSecondaryIP() {
        return secondaryIP;
    }
    public void setSecondaryIP(String secondaryIP) {
        this.secondaryIP = secondaryIP;
    }
    
    public int getLoginFlag() {
        return loginFlag;
    }
    public void setLoginFlag(int loginFlag) {
        this.loginFlag = loginFlag;
    }
    
    public int getLoginCount() {
        return loginCount;
    }
    public void setLoginCount(int loginCount) {
        this.loginCount = loginCount;
    }

    public int getID() {
        return iD;
    }
    public void setID(int iD) {
        this.iD = iD;
    }

   public Set<UserGroupVO> getUserGroupVO() {
        return userGroupVO;
    }
    public void setUserGroupVO(Set<UserGroupVO> userGroupVO) {
        this.userGroupVO = userGroupVO;
    }
    
    public boolean getViewFlag(){
        return viewFlag;
    }
    public boolean getEditFlag(){
        return editFlag;
    }
    public boolean getDeleteFlag(){
        return deleteFlag;
    }
    
    /*public void processMenuFlag(String menuKey){
        try {
            WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(ServletActionContext.getServletContext());
            UserGroupPermissionLoader usrGrpPermLdr = (UserGroupPermissionLoader)ctx.getBean("userGroupPermissionLoader");
            if(usrGrpPermLdr != null){
                UserGroupPermission ugp = usrGrpPermLdr.getUserGroupPermission(menuKey);
                if(ugp != null){
                    System.out.println("[UserVO.processMenuFlag] UserGroupPermission for menuKey : " + menuKey + " Not Null");
                    viewFlag = ugp.isViewable();
                    editFlag = ugp.isUpdatable();
                    deleteFlag = ugp.isDeletable();
                } else{
                    System.out.println("[UserVO.processMenuFlag] UserGroupPermission for menuKey : " + menuKey + " Is Null");
                    defaultMenuFlag();
                }
            }
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }*/
    
    public void defaultMenuFlag(){
        viewFlag = false;
        editFlag = false;
        deleteFlag = false;
    }
//    public void processMenuFlag(int menuId){
//        boolean isProcess = false;
//        if(menuId > 0 && userGroup != null && userGroup.iterator().hasNext()){
//            int userGroupId = ((UserGroup)userGroup.iterator().next()).getId();
//            try {
//                WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(ServletActionContext.getServletContext());
//                RepoService rs = (RepoService)ctx.getBean("repoService");
//                int mainMenuId = Integer.parseInt(String.valueOf(menuId).substring(0, 1));
//                List resultL = rs.getUserGrpPermissionMenu(mainMenuId, userGroupId);
//                if(resultL != null){
//                    for(Iterator iterator = resultL.iterator(); iterator.hasNext();){
//                        SubMenu1ConfigVO subMenu1 = (SubMenu1ConfigVO)iterator.next();
//                        if(subMenu1 != null && (subMenu1.getSubMenu1Id() == menuId || subMenu1.getSubMenu2Id() == menuId)){
//                            viewFlag = subMenu1.isViewFlag();
//                            editFlag = subMenu1.isUpdateFlag();
//                            deleteFlag = subMenu1.isDeleteFlag();
//                            isProcess = true;
//                            System.out.println("[UserVO.processMenuFlag] menuId : " + menuId + " (view="+viewFlag+",edit="+editFlag+",del="+deleteFlag+")");
//                            break;
//                        }
//                    }
//                }
//            } catch(RepoServiceException ex) {
//                ex.printStackTrace();
//            }
//        }
//        if(!isProcess){
//            viewFlag = true;
//            editFlag = false;
//            deleteFlag = false;
//            System.out.println("[UserVO.processMenuFlag] Not found menuId : " + menuId + " for set flag !");
//        }
//    }

	public int getOrgId() {
		return orgId;
	}

	public void setOrgId(int orgId) {
		this.orgId = orgId;
	}
    
}
